class Solution {
public:
    int calculate(string s) {
char h= '+';
        int n= 0;    
        vector<int> v;

        for(int i = 0 ; i < s.size(); ++i)
        {
                        
            if(  isdigit(s[i]) ){ n = 10*n + (s[i] - '0'); }
            if( (!isdigit(s[i]) && s[i]!= ' ') || i == s.size() - 1){
                if( h == '+' ){ v.push_back(+n); }
                if( h == '-' ){ v.push_back(-n); }
                if( h == '*' ){ 
                    int t = v.back()*n; 
                     v.pop_back();   
                     v.push_back(t); 
                }
                if( h == '/' ){ 
                    int t = v.back()/n; 
                    v.pop_back();   
                    v.push_back(t); 
                }                
                h = s[i];
                n = 0;
            }
        }

        int r = 0;
        for( auto n : v ){ r += n; }
        return r;
    }
};
